import {Component} from '@angular/core';
import {NavController, NavParams} from 'ionic-angular';

import {Backend} from '../../providers/backend';

import {TabMy} from './tab-my';

@Component({
  templateUrl: 'build/pages/tab-my/tab-my-information.html'
})
export class Information {

  static get parameters() {
    return [[NavController], [NavParams], [Backend]];
  }

  constructor(nav, params, backend) {
    this.nav = nav;
    this.params = params;
    this.backend = backend;
    this.uid = params.get('uid');
    this.person;
    this.wrongmessage;
    this.title1;
    this.title2;
    this.firstname ;
    this.lastname;
    this.email = params.get('email');
    this.mobilenumber;
    this.industrytype;
    this.company;
    this.companyname;
    this.department;
    this.jobtitle;
    this.contact;
    this.fullname;
    this.contactEmail;
    this.backend.loginsuccess(this.uid)
      .then(result => {
        this.contents = result.result[0];
        console.log(this.contents);
        this.title1 = this.contents.title;
        this.firstname = this.contents.fname;
        this.lastname = this.contents.lname;
        this.mobilenumber = this.contents.phone;
        this.industrytype = this.contents.itype;
        this.companyname = this.contents.company;
        this.department= this.contents.department;
        this.jobtitle = this.contents.jobtitle;
        this.title2= this.contents.ctitle;
        this.fullname = this.contents.truename;
        this.contactEmail = this.contents.cemail;
      });
    

  }
  submit() {
    this.title1 = this.person;
    this.industrytype = this.company;
    this.title2 = this.contact;
    this.data = {
      'truename': this.fullname,
      'phone': this.mobilenumber, 
      'company': this.companyname,
      'itype':this.company,
      'fname': this.firstname,
      'lname': this.lastname,
      'title': this.title1,
      'department': this.department,
      'jobtitle': this.jobtitle,
      'cemail': this.contactEmail,
      'ctitle': this.title2
    };
    this.backend.submit(this.uid, this.data)
      .then(result => {
        this.suvery = result;
        console.log(this.suvery);
        if(this.suvery.code == 3){
          this.nav.pop();
        }else if(this.suvery.code == 1){
          this.wrongmessage='非法字段';
        }else{
          this.wrongmessage='修改失败';
        }
        
      });
  }
}
